package org.jeecgframework.web.controller;

import com.mybatis.ext.WiseCoreService;
import org.jeecgframework.core.common.exception.BusinessException;
import org.jeecgframework.core.common.model.json.AjaxJson;
import org.jeecgframework.core.common.model.json.DataGrid;
import org.jeecgframework.core.constant.Globals;
import org.jeecgframework.core.util.ResourceUtil;
import org.jeecgframework.core.util.StringUtil;
import org.jeecgframework.core.util.oConvertUtils;
import org.jeecgframework.tag.core.easyui.TagUtil;
import org.jeecgframework.web.service.CbsInspectionEvaluateServiceI;
import org.jeecgframework.web.service.ZyCommonService;
import org.jeecgframework.web.service.ZyInspectionPlanServiceI;
import org.jeecgframework.web.service.ZyPlanRecordServiceI;
import org.jeecgframework.web.system.pojo.base.*;
import org.jeecgframework.web.system.service.SystemService;
import org.jeecgframework.web.util.StaticValue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;

/**
 * Created by 大伟 on 2016/11/14.
 * Description
 */
@Controller
@RequestMapping("cbsInspectionEvaluateController")
public class CbsInspectionEvaluateController {

    @Autowired
    private CbsInspectionEvaluateServiceI cbsInspectionEvaluateService;

    @Autowired
    private WiseCoreService wiseCoreService;

    @Autowired
    private ZyInspectionPlanServiceI zyInspectionPlanService;

    @Autowired
    private ZyCommonService zyCommonService;

    @Autowired
    private SystemService systemService;

    @Autowired
    private ZyPlanRecordServiceI zyPlanRecordService;

    private static String prefix = "com/zybk/cbs_evaluate/";

    @RequestMapping(params = "list")
    public String goList() {
        return prefix + "evaluateList";
    }

    @RequestMapping(params = "datagrid")
    public void datagrid(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
        cbsInspectionEvaluateService.queryEvaluateData(request, response, dataGrid);
    }

    /**
     * 首页点击 巡检服务未评价 数量 跳转进来的
     */
    @RequestMapping(params = "listOfHomePageTask")
    public String listOfHomePageTask(HttpServletRequest request) {
        String homePageType = oConvertUtils.getString ( request.getParameter ( "homePageType" ) );
        request.setAttribute ( "homePageType", homePageType );
        return prefix + "evaluateListOfHomePage";
    }

    /**
     * 首页点击 巡检服务未评价 数量 跳转进来的 datagrid
     */
    @RequestMapping(params = "datagridOfHomePage")
    public void datagridOfHomePage(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
        Map param = new HashMap<> ();
        param.put ( "evaluateState", StaticValue.DIC_EVALUATE_STATE_0 );

        if (StringUtil.isNotEmpty ( request.getParameter ( "homePageType" ) )) {
            String homePageType = request.getParameter ( "homePageType" );
            if (homePageType.equals ( "hd_ipHadNoIeOverTime" )) {
                //任务提醒： HD咨询线： 巡检满意度回访超时任务提醒：巡检结束时间后超过一周(7)而尚未进行服务评价的巡检计划数量。
                /*StringBuffer sql = new StringBuffer();
				sql.append(" SELECT ");
				sql.append(" 	ip.id AS ipId ");
				sql.append(" FROM ");
				sql.append(" 	zy_inspection_plan ip ");
				sql.append(" LEFT JOIN cbs_inspection_evaluate ie ON ie.inspection_id = ip.id ");
				sql.append(" WHERE  ");
				sql.append(" 	ISNULL(ie.id) ");
				sql.append(" 	AND TIMESTAMPDIFF(DAY,NOW(),ip.end_time) > ? ");*/
                param.put ( "ieOverAWeek", 7 );
            }
        }
        for (Object key : request.getParameterMap ().keySet ()) {
            if ((String[]) request.getParameterMap ().get ( key ) != null) {
                for (int i = 0; i < ((String[]) request.getParameterMap ().get ( key )).length; i++) {
                    if (((String[]) request.getParameterMap ().get ( key ))[i] != null) {
                        param.put ( key, ((String[]) request.getParameterMap ().get ( key ))[i].trim() );
                    }
                }
            }
        }
        wiseCoreService.selectDataGrid ( "selectEvaluate", param, dataGrid );
        TagUtil.datagrid ( response, dataGrid );
    }

    @RequestMapping(params = "detailsOfPlan")
    public ModelAndView detailsOfPlan(String planId, HttpServletRequest request) {
        String hql = "from ZyInspectionPlanEntity where planId=?";
        List<ZyInspectionPlanEntity> plans = systemService.findHql ( hql, oConvertUtils.getString ( planId ) );
        if (plans.size () > 0) {
            ZyInspectionPlanEntity zyIP = plans.get ( 0 );
            if (null != zyIP.getIpPlanDate ()) {
                Calendar cal = Calendar.getInstance ();
                cal.setTime ( zyIP.getIpPlanDate () );
                zyIP.setIpMonth ( cal.get ( Calendar.MONTH ) + 1 + "" );//因为 ipMonth不是数据库字段，这里需要根据计划巡检日期 算出来 计划巡检月份
            }
            request.setAttribute ( "zyIP", zyIP );
            //按钮 取消 巡检计划 的 过滤条件
            List<String> btnCancelPlanRules = new ArrayList<String> ();
            btnCancelPlanRules.add ( StaticValue.DIC_PLAN_STATE_TODO );
            btnCancelPlanRules.add ( StaticValue.DIC_PLAN_STATE_SEND_TO_THIRDPARTY );
            btnCancelPlanRules.add ( StaticValue.DIC_PLAN_STATE_THIRDPARTY_REFUSED );
            btnCancelPlanRules.add ( StaticValue.DIC_PLAN_STATE_THIRDPARTY_ASSIGNED );
            btnCancelPlanRules.add ( StaticValue.DIC_PLAN_STATE_AREA_ENGINEER_REFUSED );
            btnCancelPlanRules.add ( StaticValue.DIC_PLAN_STATE_AREA_ENGINEER_ASSIGNED );
            btnCancelPlanRules.add ( StaticValue.DIC_PLAN_STATE_ENGINEER_REFUSED );
            btnCancelPlanRules.add ( StaticValue.DIC_PLAN_STATE_ENGINEER_ASSIGNED );
            btnCancelPlanRules.add ( StaticValue.DIC_PLAN_STATE_ENGINEER_IN_IMPLEMENT );
            boolean btnCanCancel = false;
            if (btnCancelPlanRules.contains ( zyIP.getState () )) {
                btnCanCancel = true;
            }
            request.setAttribute ( "btnCanCancel", btnCanCancel );
            //巡检单位
            List<TSDepart> tsDeparts = zyCommonService.queryOrgByOrgTypeAndBusScope ( StaticValue.DIC_ORG_TYPE_THIRD_PARTY, StaticValue.DIC_BUS_SCOPE_INSPECTION );
            request.setAttribute ( "tsDeparts", tsDeparts );
            Calendar cal = Calendar.getInstance ();
            int currMonth = cal.get ( Calendar.MONTH ) + 1;
            request.setAttribute ( "currMonth", currMonth );
//            if (zyIP.getState ().equals ( StaticValue.DIC_PLAN_STATE_THIRDPARTY_REFUSED )) {//如果是第三方拒绝了任务。这里可以重新指派，所以跳转到分配页面，其中也可以取消巡检计划
//                ZyEquipmentSpareEntity zyEquipmentSpare = zyIP.getEquipmentSpare ();
//                request.setAttribute ( "zyEquipmentSparePage", zyEquipmentSpare );
//                return new ModelAndView ( "com/zybk/zy_inspection_plan/zyGeneratePlan" );
//            }
            TSType tsType = zyCommonService.queryTsType ( StaticValue.DIC_PLAN_STATE, zyIP.getState () );
            zyIP.setStateVal ( null != tsType ? tsType.getTypename () : "" );
            //设备单拿出来
            request.setAttribute ( "zyES", zyIP.getEquipmentSpare () );
            //巡检流程 进度
            request.setAttribute ( "planStateProcessBeans", zyPlanRecordService.queryPlanStateProcess ( zyIP.getId () ) );
            //影院巡检联系人单查
            String cinemaId = zyIP.getEquipmentSpare ().getZyCinema () != null ? zyIP.getEquipmentSpare ().getZyCinema ().getId () : "";
            ZyContactsEntity zyContact = zyInspectionPlanService.queryCinemaInspectionContact ( cinemaId );
            request.setAttribute ( "zyContact", zyContact );
            //银幕类型 取字典对应值
            if (null != zyIP.getEquipmentSpare ().getHouse ()) {
                TSType screenType = zyCommonService.queryTsType ( StaticValue.DIC_SCREEN_TYPE, zyIP.getEquipmentSpare ().getHouse ().getScreenType () );
                request.setAttribute ( "screenType", null != screenType ? screenType.getTypename () : "" );
            }
            request.setAttribute ( "btnSaveRules", StaticValue.DIC_PLAN_STATE_TODO );
            request.setAttribute ( "btnChildRules", StaticValue.DIC_PLAN_STATE_INSPECTION_COMPLETE );//只有已完成的巡检计划才可以创建子单
            //影院技术主管
            List<ZyContactsEntity> cinemaContacts =
                    systemService.findHql ( "from ZyContactsEntity where belongCinema.id =? and position =? and state = ? and isDelete = ?",
                            null != zyIP.getEquipmentSpare ().getZyCinema () ? zyIP.getEquipmentSpare ().getZyCinema ().getId () : "", StaticValue.DIC_CONTACT_POSITION_C_TECHNICAL_DIRECTOR, StaticValue.DIC_ENGINEER_STATE_ONJOB, "0" );
            request.setAttribute ( "cmContactTechnicalDirector", cinemaContacts != null && cinemaContacts.size () > 0 ? cinemaContacts.get ( 0 ) : "" );
            //是否显示 按钮查看巡检报告和修改巡检报告 标示
            request.setAttribute ( "viewOrUpdateReportFlag", zyInspectionPlanService.judgeViewOrUpdateReport ( zyIP.getId () ) );
        }

        return new ModelAndView ( "com/zybk/zy_inspection_plan/zyInspectionPlanDetials-form-evaluate" );
    }

    /**
     * 服务评价报表 - 点击数字跳转
     */
    @RequestMapping(params = "ieListOfIeReport")
    public ModelAndView ieListOfIeReport(HttpServletRequest request) {
        String type = oConvertUtils.getString ( request.getParameter ( "type" ) );
        String score = oConvertUtils.getString ( request.getParameter ( "score" ) );
        String ipCompany = oConvertUtils.getString ( request.getParameter ( "ipCompany" ) );
        String year = oConvertUtils.getString ( request.getParameter ( "year" ) );
        String month = oConvertUtils.getString ( request.getParameter ( "month" ) );//month 和 egId只会同时存在一个（分别对应第三方满意度tab和工程师满意度tab）
        String egId = oConvertUtils.getString ( request.getParameter ( "egId" ) );
        request.setAttribute ( "params", "score=" + score + "&year=" + year + "&ipCompany=" + ipCompany + "&month=" + month + "&egId=" + egId );
        if(StringUtil.isNotEmpty(type) && type.equals("3") ||  type.equals("4")){//维修服务评价
            return new ModelAndView ( "com/zybk/cbs_evaluate/ieListOfIeRepairReport" );
        }
        return new ModelAndView ( "com/zybk/cbs_evaluate/ieListOfIeReport" );
    }

    /**
     * 服务评价报表 - 点击数字跳转  - datagrid
     */
    @RequestMapping(params = "datagridOfIeListOfIeReport")
    public void datagridOfIeListOfIeReport(CbsInspectionEvaluateEntity cbsIeEntity, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
        try {
            //从服务评价报表跳转过来的
            if (StringUtil.isNotEmpty ( request.getParameter ( "score" ) ) && //这三个条件必须有 ipCompany 可以没有
                    StringUtil.isNotEmpty ( request.getParameter ( "year" ) ) &&
                    (StringUtil.isNotEmpty ( request.getParameter ( "month" ) ) || StringUtil.isNotEmpty ( request.getParameter ( "egId" ) ))) {
                cbsInspectionEvaluateService.datagridOfIeListOfIeReport ( request, dataGrid );
            } else {
                dataGrid.setResults ( new ArrayList<> () );
            }
        } catch (Exception e) {
            throw new BusinessException ( e.getMessage () );
        }
        TagUtil.datagrid ( response, dataGrid );
    }
    /**
     * 服务评价报表 - 点击数字跳转  - datagrid
     * 维修服务
     */
    @RequestMapping(params = "datagridOfIeListOfIeRepairReport")
    public void datagridOfIeListOfIeRepairReport(CbsInspectionEvaluateEntity cbsIeEntity, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
        try {
            //从服务评价报表跳转过来的
            if (StringUtil.isNotEmpty ( request.getParameter ( "score" ) ) && //这三个条件必须有 ipCompany 可以没有
                    StringUtil.isNotEmpty ( request.getParameter ( "year" ) ) &&
                    (StringUtil.isNotEmpty ( request.getParameter ( "month" ) ) || StringUtil.isNotEmpty ( request.getParameter ( "egId" ) ))) {
                cbsInspectionEvaluateService.datagridOfIeListOfIeRepairReport ( request, dataGrid );
            } else {
                dataGrid.setResults ( new ArrayList<> () );
            }
        } catch (Exception e) {
            throw new BusinessException ( e.getMessage () );
        }
        TagUtil.datagrid ( response, dataGrid );
    }

    /**
     * @author xiul
     * 2017-5-15 上午10:55:38
     * Description 服务评价报表 - 点数字跳转的列表页的 详情按钮跳转
     */
    @RequestMapping(params = "goEvaluateDetail")
    public ModelAndView goEvaluateDetail(HttpServletRequest request) {
        String id = oConvertUtils.getString ( request.getParameter ( "id" ) );
        String type = oConvertUtils.getString ( request.getParameter ( "type" ) );
        String cmName = oConvertUtils.getString ( request.getParameter ( "cmName" ) );
        request.setAttribute ( "id", id );
        request.setAttribute ( "cmName", cmName );
        /**报表带来的条件*/
        String score = oConvertUtils.getString ( request.getParameter ( "score" ) );
        String ipCompany = oConvertUtils.getString ( request.getParameter ( "ipCompany" ) );
        String year = oConvertUtils.getString ( request.getParameter ( "year" ) );
        String month = oConvertUtils.getString ( request.getParameter ( "month" ) );//month 和 egId只会同时存在一个（分别对应第三方满意度tab和工程师满意度tab）
        String egId = oConvertUtils.getString ( request.getParameter ( "egId" ) );
        /**报表带来的条件 - end*/
        request.setAttribute ( "params", "score=" + score + "&year=" + year + "&ipCompany=" + ipCompany + "&month=" + month + "&egId=" + egId );
        if(StringUtil.isNotEmpty(type) && type.equals("3")){//维修服务评价
            return new ModelAndView ( "com/zybk/cbs_evaluate/ieRepairDetialOfIeReport" );
        }
        return new ModelAndView ( "com/zybk/cbs_evaluate/ieDetialOfIeReport" );
    }

    /**
     * @author xiul
     * 2017-5-15 上午10:59:36
     * Description 服务评价报表 - 点数字跳转的列表页的 详情页 datagrid
     */
    @ResponseBody
    @RequestMapping(params = "datagridOfIeDetialOfIeReport")
    public void datagridOfIeDetialOfIeReport(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
        try {
            cbsInspectionEvaluateService.queryIeDetialOfIeReportData ( request, dataGrid );
        } catch (Exception e) {
            throw new BusinessException ( e.getMessage () );
        }
        TagUtil.datagrid ( response, dataGrid );
    }

    /**
     * @author mhg
     * 2018-6-28
     * Description 服务评价报表 - 点数字跳转的列表页的 详情页 datagrid
     * 维修服务
     */
    @ResponseBody
    @RequestMapping(params = "datagridOfIeRepairDetialOfIeReport")
    public void datagridOfIeRepairDetialOfIeReport(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
        try {
            cbsInspectionEvaluateService.queryIeRepairDetialOfIeReportData ( request, dataGrid );
        } catch (Exception e) {
            throw new BusinessException ( e.getMessage () );
        }
        TagUtil.datagrid ( response, dataGrid );
    }

    /**
     * @author xiul
     * 2017-5-15 下午2:18:42
     * Description 服务评价报表 - 点数字跳转的列表页 - 详情页 点工程师名称跳转
     */
    @RequestMapping(params = "goViewIeEgDetial")
    public ModelAndView goViewIeEgDetial(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
        String egId = oConvertUtils.getString ( request.getParameter ( "egId" ) );
        request.setAttribute ( "egId", egId );
        /**报表带来的条件*///只留一个年份
        String year = oConvertUtils.getString ( request.getParameter ( "year" ) );
        /**报表带来的条件 - end*/
        request.setAttribute ( "params", "year=" + year );

        String type = oConvertUtils.getString ( request.getParameter ( "type" ) );
        request.setAttribute ( "type", type);
        return new ModelAndView ( "com/zybk/cbs_evaluate/egDitailOfIeDetialOfIeReport" );
    }

    /**
     * @author xiul
     * 2017-5-15 下午2:23:57
     * Description 服务评价报表 - 点数字跳转的列表页 - 详情页 点工程师名称跳转 datagrid
     */
    @ResponseBody
    @RequestMapping(params = "datagridOfEgDitailOfIeDetialOfIeReport")
    public void datagridOfEgDitailOfIeDetialOfIeReport(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
        try {
            cbsInspectionEvaluateService.queryEgDitailOfIeDetialOfIeReport ( request, dataGrid );
        } catch (Exception e) {
            throw new BusinessException ( e.getMessage () );
        }
        TagUtil.datagrid ( response, dataGrid );
    }

    /**
     * @author xiul
     * 2017-5-15 下午2:23:57
     * Description 服务评价报表 - 点数字跳转的列表页 - 详情页 点工程师名称跳转 datagrid
     */
    @ResponseBody
    @RequestMapping(params = "queryEgDitailOfIeRepairDetialOfIeReport")
    public void queryEgDitailOfIeRepairDetialOfIeReport(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
        try {
            cbsInspectionEvaluateService.queryEgDitailOfIeRepairDetialOfIeReport ( request, dataGrid );
        } catch (Exception e) {
            throw new BusinessException ( e.getMessage () );
        }
        TagUtil.datagrid ( response, dataGrid );
    }

    /**
     * @author xiul
     * 2017-4-28 上午10:35:37
     * Description 编辑巡检评价备注
     */
    @RequestMapping(params = "goEditRemark")
    public ModelAndView goEditRemark(HttpServletRequest request) {
        ModelAndView mv=null;
        String id =request.getParameter("id");
        CbsInspectionEvaluateEntity evaluateEntity = systemService.get ( CbsInspectionEvaluateEntity.class, oConvertUtils.getString ( id ) );
        if(StringUtil.isNotEmpty(evaluateEntity)){
            if(evaluateEntity.getBusType().equals(StaticValue.DIC_EVALUATE_BUS_TYPE_1)){  /*巡检*/
                mv = new ModelAndView ( "com/wx/personal_center/my_inspection/pc_evaluate_remark" );
            }else if (evaluateEntity.getBusType().equals(StaticValue.DIC_EVALUATE_BUS_TYPE_2)){
                mv =new ModelAndView("com/wx/personal_center/my_inspection/pc_service_evaluate_remark");
            }else if (evaluateEntity.getBusType().equals(StaticValue.DIC_EVALUATE_BUS_TYPE_3)){
                mv =new ModelAndView("com/wx/personal_center/my_inspection/pc_service_remark");
            }
            mv.addObject ( "evaluate", evaluateEntity );
        }
        return mv;
    }

    /**
     * @author xiul
     * 2017-4-28 上午10:35:37
     * Description 保存 巡检评价备注
     */
    @ResponseBody
    @RequestMapping(params = "saveRemark")
    public AjaxJson saveRemark(String id, String remark) {
        AjaxJson j = new AjaxJson ();
        try {
            CbsInspectionEvaluateEntity ie = systemService.getEntity ( CbsInspectionEvaluateEntity.class, id );
            if (ie == null) {
                j.setMsg ( "保存失败" );
            } else {
                //大伟挖的坑，未加 评价人 和 评价时间 和 评价人登录名 字段，所以这里在修改保存备注的时候不应该修改备注
//				ie.setUpdateBy(ie.getUpdateBy());
//				ie.setUpdateDate(ie.getUpdateDate());
//				ie.setUpdateName(ie.getUpdateName());
                ie.setRemark ( remark );
                systemService.saveOrUpdate ( ie );
            }
        } catch (Exception e) {
            e.printStackTrace ();
            j.setSuccess ( false );
        }
        return j;
    }

    /**
     * @author xiul
     * 2017-5-3 上午10:34:40
     * Description 巡检
     */
    @ResponseBody
    @RequestMapping
    public void exportIe(HttpServletRequest request, HttpServletResponse response) {
                cbsInspectionEvaluateService.exportIe ( request, response );
    }

    /**
     * @author mhg
     * 跳转到填写维修服务评价页面
     */
    @RequestMapping(params = "goRepairEvaluate")
    public ModelAndView goRepairEvaluate(HttpServletRequest request) {

        String id=request.getParameter("id");
        CbsServiceEntity service=systemService.get(CbsServiceEntity.class,id);
        request.setAttribute("service",service);

        //获取服务商信息
        if(service!=null){
            TSDepart ts=systemService.singleResult("from TSDepart where orgCode='"+service.getServiceProviderCode()+"'");
            request.setAttribute("ts",ts);

            //获取工程师信息
            if(StringUtil.isNotEmpty(service.getEngineer())){
                ZyEngineerEntity engineer=systemService.get(ZyEngineerEntity.class,service.getEngineer());
                request.setAttribute("engineer",engineer);
            }
        }

        return new ModelAndView ( "com/wx/personal_center/my_inspection/repairService_evaluate" );
    }


    /**
     * @author mhg
     * 填写维修服务评价
     */
    @RequestMapping(params = "doRepairEvaluate")
    @ResponseBody
    public AjaxJson doRepairEvaluate(HttpServletRequest request) {
        AjaxJson j = new AjaxJson ();
        TSUser user= ResourceUtil.getSessionUserName();
        String  message="success";
        CbsInspectionEvaluateEntity evaluate=null;
        String id=request.getParameter("serviceId");
        try {
            List<CbsInspectionEvaluateEntity> evaluateEntity=systemService.findHql("from CbsInspectionEvaluateEntity where busType='type_2' and cbsService.id='"+id+"'");
            if(evaluateEntity!=null && evaluateEntity.size()>0){
                evaluate=evaluateEntity.get(0);
            }else{
                evaluate=new CbsInspectionEvaluateEntity();
            }
            String lastEvaluate=request.getParameter("lastEvaluate");
            String serviceEvaluate=request.getParameter("serviceEvaluate");
            String talkEvaluate=request.getParameter("talkEvaluate");
            String effectEvaluate=request.getParameter("effectEvaluate");
            String trainEvaluate=request.getParameter("trainEvaluate");
            String skillEvaluate=request.getParameter("skillEvaluate");
            if(StringUtil.isNotEmpty(id)){
                CbsServiceEntity service=systemService.get(CbsServiceEntity.class,id);
                evaluate.setCbsService(service);
            }
            evaluate.setBusType(request.getParameter("busType"));
            evaluate.setLastEvaluate(Integer.valueOf(lastEvaluate));
            evaluate.setServiceEvaluate(Integer.valueOf(serviceEvaluate));
            evaluate.setTalkEvaluate(Integer.valueOf(talkEvaluate));
            evaluate.setEffectEvaluate(Integer.valueOf(effectEvaluate));
            evaluate.setTrainEvaluate(Integer.valueOf(trainEvaluate));
            evaluate.setSkillEvaluate(Integer.valueOf(skillEvaluate));
            evaluate.setOpinion(request.getParameter("opinion"));
            evaluate.setEvaluateTime(new Date());
            evaluate.setEvaluateName(user.getRealName());
            evaluate.setEvaluateState(StaticValue.DIC_EVALUATE_STATE_1);
            systemService.saveOrUpdate(evaluate);
        } catch (Exception e) {
            e.printStackTrace ();
            message="fail";
        }

        j.setMsg(message);
        return j;
    }

    /**
     * 跳转到维修服务评价列表页面
     * @author mhg
     * 时间：2018-04
     */
    @RequestMapping(params = "goRepairEvaluateList")
    public ModelAndView goRepairEvaluateList(HttpServletRequest request) {

        TSUser user=ResourceUtil.getSessionUserName();
        String userName="";
        if(user!=null){
            userName=user.getUserName();
        }

        String phone="";
        if(user!=null){
            phone=user.getMobilePhone();
        }

        System.out.println("userName:"+userName);
//        CbsWxUserBindEntity wxUser=systemService.singleResult("from CbsWxUserBindEntity where openId='"+user.getOpenId()+"'");

        CbsServiceTypeEntity serviceType1=systemService.singleResult("from CbsServiceTypeEntity where name='故障维修' and type=0");
        String serviceTypeId="";
        if(serviceType1!=null){
            serviceTypeId=serviceType1.getId();
        }

        //查询该用户电话报修的已完成的维修服务单及评价
        String sql="SELECT\n" +
                "\tcs.`code` AS code,\n" +
                "\tcs.`id` AS id,\n" +
                "eva.last_evaluate AS lastEvaluate,\n" +
                "eva.evaluate_state AS evaluateState\n" +
                "FROM\n" +
                "\tcbs_service cs\n" +
                "LEFT JOIN cbs_inspection_evaluate eva ON eva.cbsservice_id=cs.id\n" +
                "WHERE\n" +
                "\tcs.contacts_phone = '"+phone+"'\n" +
                "AND cs.service_type_1 = '"+serviceTypeId+"'\n" +
                "AND cs. STATUS = '4'\n" +
                "AND cs.create_date > DATE_SUB(CURDATE(), INTERVAL 3 MONTH)\n" +
                "ORDER BY\n" +
                "eva.evaluate_state ASC,\n" +
                "\teva.create_date DESC";
        List<Map<String,Object>> qrs = systemService.findForJdbc(sql);
        request.setAttribute("qrs", qrs);
        request.setAttribute("user", user);


        return new ModelAndView ( "com/wx/personal_center/my_inspection/repair_evaluate_list" );
    }
    /**
     * 跳转到维修服务评价详情页面
     * @author mhg
     * 时间：2018-04
     */
    @RequestMapping(params = "goRepairEvaluateDetail")
    public ModelAndView goRepairEvaluateDetail(HttpServletRequest request) {

        String serviceId=request.getParameter("serviceId");
        if(StringUtil.isNotEmpty(serviceId)){
            CbsServiceEntity service=systemService.get(CbsServiceEntity.class,serviceId);
            request.setAttribute("service",service);
            if(service!=null){
                //获取服务商信息
                TSDepart ts=systemService.singleResult("from TSDepart where orgCode='"+service.getServiceProviderCode()+"'");
                request.setAttribute("ts",ts);
                //获取工程师信息
                if(StringUtil.isNotEmpty(service.getEngineer())){
                    ZyEngineerEntity engineer=systemService.get(ZyEngineerEntity.class,service.getEngineer());
                    request.setAttribute("engineer",engineer);
                }
            }

        }

        CbsInspectionEvaluateEntity evaluate=systemService.singleResult("from CbsInspectionEvaluateEntity where busType='type_2' and cbsService.id='"+serviceId+"'");
        request.setAttribute("evaluate",evaluate);

        return new ModelAndView ( "com/wx/personal_center/my_inspection/repairService_evaluate_detail" );
    }


}
